<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>axios</title>
    <script src="https://cdn.jsdelivr.net/npm/axios@1.1.2/dist/axios.min.js"></script>
</head>
<body>
<button>发送get请求</button>
<button>取消get请求</button>
<script>
    var controller = null
    let btns = document.querySelectorAll('button');
    btns[0].addEventListener('click', function () {
        controller = new AbortController();
        axios({
            method: 'get',
            url: 'http://localhost:3000/posts/1',
            signal: controller.signal,
        }).then((value) => {
            console.log(value);
        });
    })
    btns[1].addEventListener('click', function () {
        controller.abort();
        controller = null
    })
</script>
</body>
</html>